<extend name="./public/frame.html"/>
<block name="content">
<form class="layui-form layui-form-pane1" action="" method="post">
  <div class="layui-form-item">
    <label class="layui-form-label">活动名称</label>
    <div class="layui-input-block">
      <input type="text" name="title" lay-verify="required|title" required placeholder="请输入活动名称" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">金额(元)</label>
    <div class="layui-input-block">
      <input type="num" name="money" lay-verify="number" autocomplete="off" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">活动日期</label>
      <div class="layui-input-inline" style="width: 200px;">
        <input type="text" name="start_time" lay-verify="required|start_time"  class="layui-input" id="test6-1">
      </div>
      <div class="layui-form-mid">-</div>
      <div class="layui-input-inline" style="width: 200px;">
        <input type="text" name="end_time" lay-verify="required|end_time" class="layui-input" id="test6-2">
      </div>
    </div>
  </div>
  <div class="layui-form-item" pane>
    <label class="layui-form-label">推送城市</label>
    <div class="layui-input-block fa">
      <input type="checkbox" data-type="all" title="全部" lay-verify="required|region">
   
		<volist name="list" id="v">
			<input type="checkbox" name="region[]" title="{$v.city_name}" value="{$v.region_id}" class="item_child" >
		</volist>
    
      
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">请填写活动描述</label>
    <div class="layui-input-block">
      <textarea placeholder="请输入内容" class="layui-textarea" name="comment"></textarea>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script>
	// $('#check-all').click(function(){
	// 	alert('adfkdjf');
	// 	if($(this).is(":checked")){
	// 			//$('input').prop('checked',true);
	// 			$('input[type=checkbox]').prop('checked',true)
	// 		}
	// 		else{
	// 		//	$('input').prop("checked",false);
	// 			$('input[type=checkbox]').prop('checked',false)
	// 		}
	// }) 
</script>
<script>
layui.use('laydate', function(){
  var laydate = layui.laydate;
  
  //墨绿主题
  laydate.render({
	elem: '#test6-1' //指定元素
	,type: 'date'
	,theme: 'molv'
	//,range: true
	,trigger: 'click'
  });
  
	laydate.render({
	elem: '#test6-2' //指定元素
	,type: 'date'
	,theme: 'molv'
	//,range: true
	,trigger: 'click'
  });
 
});
layui.use('form', function(){
  var form = layui.form;
  
  //自定义验证规则
  // form.verify({
  //   title: function(value){
  //     if(value.length < 5){
  //       return '标题也太短了吧';
  //     }
  //   }
  //   ,pass: [/(.+){6,12}$/, '密码必须6到12位']
  // });

  
  //事件监听
  form.on('select', function(data){
    console.log(this);
  })
  
  form.on('select(aihao)', function(data){
    console.log(data);
  });
  
  form.on('checkbox', function(data){
  	var type = $(this).data('type');
  	if(type == 'all'){
  		var child = $('.fa').find('.item_child');
	    child.each(function(index, item){
	        item.checked = data.elem.checked;
	    });
	    form.render('checkbox');

  	}
   // console.log(this.checked, data.elem.checked);
  });
  
  //监听提交
  
    form.verify({
	    title: function(value){
	      if(value.length < 1){
	        return '标题不能为空';
	      }
	    }
	    ,end_time: function(value){
	    	//return value;
	      if(value < $("input[name='start_time']").val()){
	        return '时间不一致';
	      }
	    }
	    ,region:function(value){
	    	var child = $('.fa').find('.item_child');
	    	var i=0;
		    child.each(function(index, item){
		    	if($(this).attr('checked')){
		    		i = i + parseInt($(this).val());
		       
		    	}
		    
		    });
			if(i == 0){
				return '未选择推送城市';
			}
	 
	    }
	  });
  form.on('submit(*)', function(data){
  	
  });
  
});

</script>
</block>
